/*
 * _DoCompositeObject.h
 *
 *  Created on: Oct 18, 2012
 *      Author: wtao
 */

#ifndef DOCOMPOSITEOBJECT_H_
#define DOCOMPOSITEOBJECT_H_

#include "_DoObject.h"

class _DoCompositeObject: public _DoObject
{
protected:
	_DoCompositeObject(const _DoCompositeObject&);
	_DoCompositeObject& operator=(const _DoCompositeObject&);

	typedef std::vector< CRefPtr < _DoObject > > CObjectList;
	CObjectList mSubObjects;

public:
	enum eAccessType {
		eUnlimited,
		eReadOnly,
		eExecuteOnly,
		eNone
	};
	eAccessType mAccType;
public:
	_DoCompositeObject();
	virtual ~_DoCompositeObject();

	virtual size_t size() const;

	void add(CRefPtr <_DoObject > obj);

	void insert(size_t i, CRefPtr <_DoObject > obj);

	CRefPtr <_DoObject > get(size_t i);

	void set(size_t i, CRefPtr <_DoObject > obj);

	CRefPtr <_DoObject > remove(size_t i);

	virtual void clear();

	eAccessType accessType() {
		return mAccType;
	}

	void setAccessType(eAccessType type) {
		mAccType = type;
	}
	
	virtual std::string _debug_dump() const {
		std::ostringstream oss;

		oss << "(" << size() << ") ";
		for (size_t i = 0; i < size(); i++) {
			CRefPtr< _DoObject > obj = mSubObjects.at(i);
			if (i != size() - 1)
				oss << obj->_debug_dump().c_str() << ", ";
			else
				oss << obj->_debug_dump().c_str();
		}

		return oss.str();
	}
};

#endif /* DOCOMPOSITEOBJECT_H_ */
